package alarmdisplay;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.LineBorder;

public class Anzeige extends GuiBase {
	private static final long serialVersionUID = 1L;
	private static int iDarstellung = 0;

	JPanel panel_top;
	JPanel panel_center;
	JPanel panel_left;

	/**
	 * main() zum Aufruf via CLI.
	 */
	public static void main(String[] args) {
		Datenbank db = new Datenbank();
		iPort = Integer.parseInt(db.dbQueryConfig("anzeige_service_port"));
		iDelay = Integer.parseInt(db.dbQueryConfig("anzeige_service_delay"));
		iDarstellung = Integer.parseInt(db.dbQueryConfig("anzeige_darstellung"));
		System.setProperty("proxySet", db.dbQueryConfig("proxy_set"));
		System.setProperty("proxyHost", db.dbQueryConfig("proxy_host"));
		System.setProperty("proxyPort", db.dbQueryConfig("proxy_port"));
		
		if (iDarstellung==2) {
			Anzeige2.main(new String[]{});
			System.exit(0);
		}
		if (iDarstellung==3) {
			Anzeige3.main(new String[]{});
			System.exit(0);
		}
		new Anzeige();
	}

	/**
	 * Konstruktor ohne Argumente.
	 */
	public Anzeige() {
		super();
		initGraphics();
		listen();
	}

	/**
	 * Initialisieren des JFrames, erstellen eines WindowListeners.
	 */
	public void initGraphics() {
		for (int x = 0; x < MAX_BUTTON; x++) {
			jb[x] = new JButton();
		}

		frame=this;
		this.setTitle("Anzeige V1.0");
		this.addComponentListener(new ComponentAdapter() {
			// TODO
			@Override
			public void componentResized(ComponentEvent arg0) {
				panel_top.setBounds(10, 0, frame.getBounds().width - 20, 330);
				panel_left.setBounds(10, 340, 400, frame.getBounds().height - 380);
				panel_center.setBounds(420, 340, frame.getBounds().width - 390, frame.getBounds().height - 380);
			}
		});
		this.setBounds(100, 100, 800, 600);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.getContentPane().setLayout(null);

		panel_top = new JPanel();
		panel_top.setBorder(new LineBorder(new Color(0, 0, 0)));
		panel_top.setBounds(10, 0, 750, 330);
		this.getContentPane().add(panel_top);
		panel_top.setLayout(new GridLayout(0, 1, 0, 0));


		panel_left = new JPanel();
		panel_left.setBorder(new LineBorder(new Color(0, 0, 0)));
		panel_left.setBounds(10, 340, 400, 220);
		frame.getContentPane().add(panel_left);
		panel_left.setLayout(new GridLayout(0, 1, 0, 0));

		panel_center = new JPanel();
		panel_center.setBorder(new LineBorder(new Color(0, 0, 0)));
		panel_center.setBounds(400, 340, 370, 220);
		frame.getContentPane().add(panel_center);
		panel_center.setLayout(new GridLayout(0, 1, 0, 0));

		jlIcon.setIcon(imageIcon);

		panel_center.add(jlIcon);

		panel_top.add(jpa);

		for (int x = 0; x < MAX_BUTTON; x++) {
			if (jb[x] != null) {
				panel_left.add(jb[x]);
				jb[x].addActionListener(this);
			}
		}

		frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
		this.setVisible(true);

		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
//				if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(null, "Soll das Programm wirklich beendet werden?", "Programm beenden?", JOptionPane.OK_CANCEL_OPTION)) {
					System.exit(0);
//				}
			}
		});
	}
}
